﻿using System.Linq;
using CSC.FSVTracker.Domain.Abstract;
using CSC.FSVTracker.Domain.Entities;

namespace CSC.FSVTracker.Domain.Concrete
{
    /// <summary>
    /// Entity framework user repostory class.
    /// </summary>
    public class EFUserRepository : IUserRepository
    {
        /// <summary>
        /// Entity farmework Database context.
        /// </summary>
        private EFDbContext context = new EFDbContext();

        /// <summary>
        /// Gets the users.
        /// </summary>
        public IQueryable<User> Users
        {
            get { return context.Users; }
        }

        /// <summary>
        /// Saves the user.
        /// </summary>
        /// <param name="user">The user.</param>
        public void SaveUser(User user)
        {
            if (user.ID == 0)
            {
                context.Users.Add(user);
            }
            context.SaveChanges();
        }
    }
}
